﻿


function copyToClipboard(elementName) {
	var s = document.getElementById(elementName).value;
	if (window.clipboardData && clipboardData.setData) {
		clipboardData.setData("Text", s);
		alert("复制成功,快分享给好友吧!");
		document.getElementById(elementName).focus();
		document.getElementById(elementName).select();
	}
	else {
		alert("您使用的浏览器不支持复制,请手动复制.");
		document.getElementById(elementName).focus();
		document.getElementById(elementName).select();
		return;
		// You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext = meintext;

		str.data = copytext;

		trans.setTransferData("text/unicode", str, copytext.length * [[[[2]]]]);

		var clipid = Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans, null, clipid.kGlobalClipboard);
	}
}

function copyTextToClipboard(s) {
	if (window.clipboardData && clipboardData.setData) {
		clipboardData.setData("Text", s);
		alert("复制成功,快分享给好友吧!");
	}
	else {
		alert("您使用的浏览器不支持复制,请手动复制.");
		return;
	}
}


function confirmDelete(msg, url, idObj) {
	if (confirm(msg)) {
		$("body").append("<form method='post' id='_FORM_DELETE_'></form>");
		var form = $("#_FORM_DELETE_").attr("action", url);

		if (typeof (idObj) == 'number') {
			form.append("<input type='hidden' name='id' value='" + idObj + "'/>");
		} else {
		for (var key in idObj) {
				form.append("<input type='hidden' name='" + key + "' value='" + idObj[key] + "'/>");
			}
		}
		form.submit();
	}
}



   function getPageSize() {

	if (window.parent.frames[window.name] && (parent.document.getElementsByTagName('frameset').length <= 0)) {
		this.isFrame = true;
		this.doc = parent.document;
	} else {
		this.isFrame = false;
		this.doc = document;
	}

	var xScroll, yScroll, windowWidth, windowHeight;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = this.doc.scrollWidth;
		yScroll = (this.isFrame ? parent.innerHeight : self.innerHeight) + (this.isFrame ? parent.scrollMaxY : self.scrollMaxY);
	} else if (this.doc.body.scrollHeight > this.doc.body.offsetHeight){
		xScroll = this.doc.body.scrollWidth;
		yScroll = this.doc.body.scrollHeight;
	} else {
		xScroll = this.doc.getElementsByTagName("html").item(0).offsetWidth;
		yScroll = this.doc.getElementsByTagName("html").item(0).offsetHeight;
		xScroll = (xScroll < this.doc.body.offsetWidth) ? this.doc.body.offsetWidth : xScroll;
		yScroll = (yScroll < this.doc.body.offsetHeight) ? this.doc.body.offsetHeight : yScroll;
	}
	if (self.innerHeight) {
		windowWidth = (this.isFrame) ? parent.innerWidth : self.innerWidth;
		windowHeight = (this.isFrame) ? parent.innerHeight : self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = this.doc.documentElement.clientWidth;
		windowHeight = this.doc.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = this.doc.getElementsByTagName("html").item(0).clientWidth;
		windowHeight = this.doc.getElementsByTagName("html").item(0).clientHeight;
		windowWidth = (windowWidth == 0) ? this.doc.body.clientWidth : windowWidth;
		windowHeight = (windowHeight == 0) ? this.doc.body.clientHeight : windowHeight;
	}
	var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
	var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
	return new Array(pageWidth, pageHeight, windowWidth, windowHeight);
}

var Youku = new RegExp("youku\.com");
var Tudou = new RegExp("tudou\.com");
var Sina = new RegExp("sina\.com\.cn");
var kuSix = new RegExp("ku6\.com");
var FiveSix = new RegExp("56\.com");
var QQ = new RegExp("qq\.com");
var sohu = new RegExp("sohu\.com");
var sixRoom = new RegExp("6\.cn");
var fenghuang = new RegExp("ifeng.com");
var openv = new RegExp("openv");
var oneSevenOneSeven = new RegExp("17173\.com");
var cctv = new RegExp("cctv\.com");
var jidong = new RegExp("joy\.cn");
var mangguo = new RegExp("hunantv\.com");

function getSourceFromID(searchElementID, flashAddress) {
	var collection = new Array();
	collection[collection.length] = Youku;
	collection[collection.length] = Tudou;
	collection[collection.length] = Sina;
	collection[collection.length] = kuSix;
	collection[collection.length] = FiveSix;
	collection[collection.length] = QQ;
	collection[collection.length] = sohu;
	collection[collection.length] = sixRoom;
	collection[collection.length] = fenghuang;
	collection[collection.length] = openv;
	collection[collection.length] = oneSevenOneSeven;
	collection[collection.length] = cctv;
	collection[collection.length] = jidong;
	collection[collection.length] = mangguo;
	var sources = new Array();
	$("#" + searchElementID + " input:radio").each(
			function(i) {
				sources[sources.length] = this;
			}
		)
	var target;
	for (var i = 0; i < collection.length; i++) {
		if (collection[i].test(flashAddress)) {
			target = collection[i];
			break;
		}
	}
	if (target == null)
		return null;
	var strRe = target.toString();
	strRe = strRe.substr(1, strRe.length - 2);
	for (var i = 0; i < sources.length; i++) {
		if (sources[i].getAttribute("extend").indexOf(strRe) != -1) {
			sources[i]["checked"] = "checked";
			var selectResult = new Object();
			selectResult.Text = sources[i].getAttribute("text");
			selectResult.Value = sources[i].getAttribute("value");
			var resultArray = new Array();
			resultArray[0] = selectResult;
			return resultArray;
		}
	}
	return null;
}


